<template>
	<view class="container">
		<view class="search-param">
			<uni-search-bar placeholder="请输入客户名称" @confirm="search" @cancel="show" v-model="sapOrderForm.certName">
			</uni-search-bar>
		</view>

		<view class="search-results-container">
			<view v-for="(cust, index) in searchResults" :key="index" class="search-result" @tap="returnOrderApplysPage(cust)">{{ cust.certName }}</view>
		</view>

		<view style="position: fixed; bottom: 0px; width: 100%;">
			<uni-row>
				<uni-col :span="24">
					<view>
						<button @click="goToHome">返回首页</button>
					</view>
				</uni-col>
			</uni-row>
		</view>

	</view>
</template>

<script>
	import {
		listDeliCust,
	} from '@/api/tms/saleOrder'

	export default {
		created() {
		},
		data() {
			return {
				searchResults: [],
				showResults: false,
				sapOrderForm: {
					certName: "",
				},
				status: 'more',
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				page: 1,
				limit: 50,
			};
		},
		methods: {
			returnOrderApplysPage(cust) {
				// 关闭当前页面  
				uni.navigateBack({
					delta: 1,
				});
					
				uni.setStorageSync('receive', {
					receiveKunnr: cust.kunnr,
					receiveName: cust.certName,
					receiveSocialCreditCode: cust.socialCreditCode,
				});
			},
			goToHome() {
				uni.switchTab({
					url: '/pages/work/index',
				});
			},
			search() {
				this.show();
			},
			show() {
				listDeliCust({
					"pageNum": 1,
					"pageSize": 200,
					"certName": this.sapOrderForm.certName
				}).then(response => {
					this.searchResults = response.rows;
				});
			},
			onLoad() {
				this.show();
			},
		},
	};
</script>

<style>
	.container {
		dispaly: flex;
		flex-direction: row;
		flex: auto;
		background-color: #fff;
	}

	.search-param {
		background-color: #fff;
	}

	.datetime-picker-container {
		flex: 1;
		text-align: center;
		/* 将内容设置为居中 */
	}

	.search-results-container {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 200%;
		/* 设置高度为内容的高度的两倍 */
		padding: 3px;
		/* 设置内边距 */
		background-color: #fff;
		/* 设置背景色 */
		margin-bottom: 120px;
		padding-bottom: 120px;
	}

	.search-result {
		flex: 1;
		/* 使每个内部元素均等分布 */
		margin-bottom: 10px;
		/* 设置底部边距 */
		background-color: #fff;
		border-top: 4px solid #f5f5f5;
		/* 设置底部边框颜色 */
		padding: 4px;
		/* 设置内边距 */
	}

	.uni-datetime-picker-active {
		margin-bottom: 40px;
	}
</style>